﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntityObjects;
using BAL.Controller;

namespace PresentationLayer.View
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString != null)
            {
                string task = Request.QueryString["task"];
                if (task == "logout")
                    Session.RemoveAll();
            }
            if (!IsPostBack)
                lblError.Visible = false;
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            Employee emp = new Employee();
            emp.EmpId = txtEmpId.Text.Trim();
            emp.Password = txtPassword.Text.Trim();
            LoginControl control = new LoginControl();


            Employee loginEmp = control.VerifyUser(emp);
            
            if (loginEmp != null)
            {
                Session["CurrentUser"] = loginEmp;

                if (loginEmp.RoleId == 1 || loginEmp.RoleId == 2)
                {
                    Response.Redirect("~/View/DepartmentEmployee/ViewCatalogue.aspx");
                }
                else if (loginEmp.RoleId == 3)
                {
                    Response.Redirect("~/View/DepartmentEmployee/ViewCatalogue.aspx");
                }
                else if (loginEmp.RoleId == 5)
                {
                    Response.Redirect("~/View/DepartmentEmployee/ViewCatalogue.aspx");
                }
                else if (loginEmp.RoleId == 6 || loginEmp.RoleId == 7)
                {
                    Response.Redirect("~/View/StoreManager/ApproveRejectItemAdjustment.aspx");
                }
                else if (loginEmp.RoleId == 8)
                {
                    Response.Redirect("~/View/StoreClerk/ViewCatalogueForClerk.aspx");
                }
            }
            else
            {
                lblError.Text = "Login Authentication Failed!";
                lblError.Visible = true;
            }
            
        }
    }
}